//
//  CustomerDataManage.m
//  WGFGlobalHouses
//
//  Created by waiguofang on 15/5/27.
//  Copyright (c) 2015年 waiguofang. All rights reserved.
//

#import "CustomerDataManage.h"
#import "API.h"
#import "UserModal.h"
#import "StringTool.h"
#import "CustModel.h"

#define areaUrl @"192.168.2.233:8203/addr/cityorarea/"
@implementation CustomerDataManage

#pragma mark 获取用户信息
-(ResulteMod *)getCustomerInfo;
{
    NSString *url = [NSString stringWithFormat:@"%@%zd",[API urlMake:customerInfo],[UserModal shareUserModel].userId];
    
    ResulteMod *mod = [Connect doGetWithOutCaChe:url];
    
    mod.resultCode = [NSString stringWithFormat:@"%@",mod.resultDic[@"code"]];
    mod.resultTip = mod.resultDic[@"message"];
    
    if (![mod.resultCode isEqualToString:@"20003"]) {
        
        mod.resltState = ResultFail;
        if ([StringTool isBlankString:mod.resultTip]) {
           
           mod.resultTip  = ![StringTool isBlankString:mod.resultDic[@"message"]]?mod.resultDic[@"message"]:[StringTool isBlankString:mod.resultCode]?@"网络错误":[NSString stringWithFormat:@"网络错误%@",mod.resultCode];
        }
        
        mod.dataMod = nil;
        return mod;
        
    }
    
    CustModel *model = [CustModel custModelWithDict:mod.resultDic[@"customerInfoDto"]];
    mod.dataMod = model;
    
    return mod;
}


#pragma mark 修改客户信息
-(ResulteMod *)updateCustomerInfoWithCustModel:(CustModel *)model;
{
    NSString *url = [NSString  stringWithFormat:@"%@",[API urlMake:customerUpdata]];
    
//    NSDictionary *dict = @{@"address":model.address,@"validate":model.validate,@"validateName":model.validateName,@"sexName":model.sexName,@"sex":model.sex,@"avatar":model.avatar,@"consumerId":model.consumerId,@"birthday":model.birthday,@"detailId":model.detailId,@"realname":model.realname,@"mail":model.mail,@"tel":model.tel,@"account":model.account,@"areaName":model.areaName,@"area":model.area,@"cityName":model.cityName,@"city":model.city,@"mobile":model.mobile};
    
    NSDictionary *dict = @{@"consumerId":model.consumerId,@"realname":model.realname,@"avatar":model.avatar,@"mobile":model.mobile,@"mail":model.mail,@"tel":model.tel,@"state":model.city,@"stateName":model.cityName,@"city":model.area,@"cityName":model.areaName,@"address":model.address,@"validate":model.validate,@"sex":model.sex,@"sexName":model.sexName,@"birthday":model.birthday,@"account":model.account,@"detailId":model.detailId};
    
    ResulteMod *mod = [Connect doPostWithOutCaCheWithUrl:url withFormdata:dict];
    
    mod.resultCode = [NSString stringWithFormat:@"%@",mod.resultDic[@"code"]];
    mod.resultTip = mod.resultDic[@"message"];
    
    if (![mod.resultCode isEqual:@"20003"]) {
        mod.resltState = ResultFail;
        if ([StringTool isBlankString:mod.resultTip]) {
            mod.resultTip = [NSString stringWithFormat:@"网络错误%@",mod.resultCode];
        }
    }
    return mod;
}

#pragma mark 获取地区
//-(ResulteMod *)getArea;
//{
////    NSString *url =
//}

@end
